package com.zt.chatgpt.openai.service.rule.impl;

import com.zt.chatgpt.openai.annotation.LogicStrategy;
import com.zt.chatgpt.openai.model.aggregates.ChatProcessAggregate;
import com.zt.chatgpt.openai.model.aggregates.UserAccountQuotaEntity;
import com.zt.chatgpt.openai.model.entity.RuleLogicEntity;
import com.zt.chatgpt.openai.model.valobj.LogicCheckTypeVO;
import com.zt.chatgpt.openai.model.valobj.UserAccountStatusVO;
import com.zt.chatgpt.openai.service.rule.ILogicFilter;
import com.zt.chatgpt.openai.service.rule.factory.DefaultLogicFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author: zt
 * @Description: 账户状态校验过滤器
 * @create: 2024-05-22 20:15
 */
@Slf4j
@Component
@LogicStrategy(logicMode = DefaultLogicFactory.LogicModel.ACCOUNT_STATUS)
public class AccountStatusFilter implements ILogicFilter<UserAccountQuotaEntity> {
    @Override
    public RuleLogicEntity<ChatProcessAggregate> filter(ChatProcessAggregate chatProcessAggregate, UserAccountQuotaEntity data) throws Exception {
        if (UserAccountStatusVO.AVAILABLE.equals(data.getUserAccountStatusVO())) {
            return RuleLogicEntity.<ChatProcessAggregate>builder()
                    .type(LogicCheckTypeVO.SUCCESS)
                    .info("账户状态校验通过")
                    .data(chatProcessAggregate)
                    .build();
        }
        return RuleLogicEntity.<ChatProcessAggregate>builder()
                .type(LogicCheckTypeVO.REFUSE)
                .info("您的账户已冻结，暂时不可使用。如果有疑问，可以联系客户解冻账户。")
                .data(chatProcessAggregate)
                .build();
    }
}
